<?php
class Agitum_Model_Role extends Agitum_Model_Tree implements Zend_Acl_Role_Interface
{
	protected $_t_class = 'Agitum_Model_DbTable_Role';
	const GUEST_ROLE_ID = 1;
	
	public function getRoleId() {
		return $this->name;
	}

	static function findById($id) {
		$role = new Agitum_Model_Role(array('id'=>$id));
		return $role->find();
	}

	static function findByName($name) {

		$select = Zend_Registry::get('Zend_Db')->select();
		$select->from('role')
				->where('name = ?', $name);
		$row = $select->query()->fetch();

		if ( $row ) {
			$role = new Agitum_Model_Role();
			foreach ( $row as $key => $value ) {
				$role->$key = $value;
			}
			return $role;
		}

		return null;
	}
}